package cl.uchile.sti.authorization.dao;

import cl.uchile.sti.authorization.model.Pagina;
import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Julio Villane
 * Date: 12-12-12
 * Time: 08:51 AM
 */
public class PaginaDao {

    private static EntityManager entityManager = cambiarPorSpring.getEntityManager();

    private PaginaDao(){ }

    public static Pagina findID(Long id){
        return entityManager.find(Pagina.class, id);
    }
    public static List<Pagina> find(){
        Query q =  entityManager.createQuery("select p from Pagina p ");
        List <Pagina> resultado=q.getResultList();
        return resultado;
    }

    public static Pagina save(Pagina pagina) {
        if (pagina.getId() == null) {
            entityManager.persist(pagina);
            return pagina;
        } else {
            return entityManager.merge(pagina);
        }
    }

    public static void delete(Pagina pagina){
        entityManager.remove(pagina);
    }
}
